package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	// 示例1: 处理结构体
	type Person struct {
		Name string `json:"name"`
		Age  int    `json:"age"`
	}

	p := Person{
		Name: "Alice",
		Age:  30,
	}

	personJSON, err := json.Marshal(p)
	if err != nil {
		fmt.Println("Error marshaling person:", err)
		return
	}
	fmt.Println("Person JSON:", string(personJSON))

	// 示例2: 处理切片
	numbers := []int{1, 2, 3, 4, 5}
	numbersJSON, err := json.Marshal(numbers)
	if err != nil {
		fmt.Println("Error marshaling numbers:", err)
		return
	}
	fmt.Println("Numbers JSON:", string(numbersJSON))

	// 示例3: 处理映射
	m := map[string]string{
		"key1": "value1",
		"key2": "value2",
	}
	mJSON, err := json.Marshal(m)
	if err != nil {
		fmt.Println("Error marshaling map:", err)
		return
	}
	fmt.Println("Map JSON:", string(mJSON))
}
